<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/notes.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Kevin's Homepage</title>
<!-- InstanceEndEditable -->
<link href="../main.css" rel="Stylesheet">



<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>

<div id="container">

		<div id="imagehi"><img id="hi" src="../images/hi.gif" alt="picture hi" /></div>
	
  		<div id="rightcolumn">
		<div id="title">
			<h1 id="titletext">Kevin's Home</h1>
		</div>
		
		<ol id="navlinks">
			<li><a href="../index.html">Home</a></li>
			<li><a href="../aboutmyself.html">About Myself</a></li>
			<li><a href="../photoalbum/photoalbum.html">Photo Album</a></li>
			<li><a href="notes.html">Quick Notes</a></li>
			<li class="last"><a href="../links.html">Links</a></li>
		</ol>
		
	    
	<div id="leftbar">  
		<ol>
			<li><a href="c.html">C &amp; C++</a></li>
			<li><a href="java.html">Java</a></li>
			<li><a href="perl.html">Perl</a></li>
			<li><a href="centos.html">Centos</a></li>
			<li><a href="unix.html">Unix</a></li>
			<li><a href="css.html">CSS</a></li>
			<li><a href="php.html">PHP</a></li>
			<li><a href="sql.html">SQL</a></li>
			<li><a href="photoshop.html">Photoshop</a></li>
			<li><a href="windows.html">Windows</a></li>
			<li><a href="numbers.html">Numbers</a></li>
			<li><a href="misc.html">Misc</a></li>
		</ol>
	</div><!-- end of leftbar -->
	    <!-- InstanceBeginEditable name="EditRegion_submain" -->
	    <div id="main">
  <h3>Java</h3>
  
  <h4>Set CLASSPATH in windows:</h4>
  <pre class="codeblock">My Computer -> Properties -> Advanced -> Environment Variables
In user variable for Kevin, set the following:
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_07
PATH = %JAVA_HOME%\bin
CLASSPATH = %JAVA_HOME%\lib;. 
need to close and open the console again to take effect: echo %CLASSPATH%</pre>

  <h4>public static void main()</h4>
  <p class="pindent">this method does not require an object of the class exists. static method are sort like "global" methods, they are always available, but you have to use the class name to get them.</p>

  <h4>switch statement</h4>
  <p class="pindent">multi-selection base on possible value of integer variable or expression, each action is associated with the value of an constant integral expression, i.e. an constant value of type: byte, short, int or char, but not long.</p>

  <h4>Default values</h4>
  <p class="pindent">default int or boolean is not 0 or null. It may result in compilation error if not initialised, e.g.</p>

	<pre class="codeblock">int a;
if ( a==2 ) {
    ...
} 
 boolean b;
if ( b==true) {
    ...
}</pre>

	<p class="pindent">array and static variable default is initialised to its default value.</p>
	<h4><a href="http://www.uni-bonn.de/~manfear/javaprotection.php">Access Protection Modifiers or Visibility and Access Rights in Java</a></h4>
	<pre class="codeblock">package packageA;</pre>
	    <pre class="codeblock">public class Base {
 	      public String publicStr = &quot;publicString&quot;;
 	      protected String protectedStr = &quot;protectedString&quot;;
 	      String defaultStr = &quot;defaultString&quot;;
 	      private String privateStr = &quot;privateString&quot;;</pre>
	    <pre class="codeblock"> public void print() {
 	      System.out.println(&quot;packageA.Base has access to&quot;);
 	      System.out.println(&quot;    &quot; + publicStr);
 	      System.out.println(&quot;    &quot; + protectedStr);
 	      System.out.println(&quot;    &quot; + defaultStr);
 	      System.out.println(&quot;    &quot; + privateStr);</pre>
	    <pre class="codeblock"> 	      Base b = new Base(); // -- other Base instance
 	      System.out.println(&quot;    b.&quot; + b.publicStr);
 	      System.out.println(&quot;    b.&quot; + b.protectedStr);
 	      System.out.println(&quot;    b.&quot; + b.defaultStr);
 	      System.out.println(&quot;    b.&quot; + b.privateStr);
 	      }
}</pre>
	    <pre class="codeblock">--------------------------------------------------------------------------------</pre>
	    <pre class="codeblock">package packageA;</pre>
	    <pre class="codeblock">public class SubA extends Base {
 	      public void print() {
 	      System.out.println(&quot;packageA.SubA has access to&quot;);
 	      System.out.println(&quot;    &quot; + publicStr + &quot; (inherited from Base)&quot;);
 	      System.out.println(&quot;    &quot; + protectedStr + &quot; (inherited from Base)&quot;);
 	      System.out.println(&quot;    &quot; + defaultStr + &quot; (inherited from Base)&quot;);
 	      // -- not accessible - private elements are even not inherited
 	      // System.out.println(privateStr);</pre>
	    <pre class="codeblock"> Base b = new Base(); // -- other Base instance
 	      System.out.println(&quot;    b.&quot; + b.publicStr);
 	      System.out.println(&quot;    b.&quot; + b.protectedStr);
 	      System.out.println(&quot;    b.&quot; + b.defaultStr);
 	      // -- not accessible
 	      // System.out.println(b.privateStr);
 	      }
 }</pre>
	    <pre class="codeblock">--------------------------------------------------------------------------------</pre>
	    <pre class="codeblock">package packageA;</pre>
	    <pre class="codeblock">public class AnotherA {
 	      public void print() {
 	      System.out.println(&quot;packageA.AnotherA has access to&quot;);
 	      Base b = new Base();
 	      System.out.println(&quot;    b.&quot; + b.publicStr);
 	      System.out.println(&quot;    b.&quot; + b.protectedStr);
 	      System.out.println(&quot;    b.&quot; + b.defaultStr);
 	      // System.out.println(b.privateStr);
 	      }
}</pre>
	    <pre class="codeblock">--------------------------------------------------------------------------------</pre>
	    <pre class="codeblock">package packageB;
 	      import packageA.Base;</pre>
	    <pre class="codeblock">public class SubB extends Base {
 	      public void print() {
 	      System.out.println(&quot;packageB.SubB has access to&quot;);
 	      System.out.println(&quot;    &quot; + publicStr + &quot; (inherited from Base)&quot;);
 	      // -- protectedStr is inherited element -&gt; accessible
 	      System.out.println(&quot;    &quot; + protectedStr + &quot; (inherited from Base)&quot;);
 	      // -- not accessible
 	      // System.out.println(defaultStr);
 	      // System.out.println(privateStr);</pre>
	    <pre class="codeblock"> Base b = new Base(); // -- other Base instance
 	      System.out.println(&quot;    b.&quot; + b.publicStr);
 	      // -- protected element, which belongs to other object -&gt; not accessible
 	      // System.out.println(b.protectedStr);</pre>
	    <pre class="codeblock"> // -- not accessible
 	      // System.out.println(b.defaultStr);
 	      // System.out.println(b.privateStr);
 	      }
}</pre>
	    <pre class="codeblock">--------------------------------------------------------------------------------</pre>
	    <pre class="codeblock">package packageB;
 	      import packageA.Base;</pre>
	    <pre class="codeblock">public class AnotherB {
 	      public void print() {
 	      System.out.println(&quot;packageB.AnotherB has access to&quot;);
 	      Base b = new Base();
 	      System.out.println(&quot;    b.&quot; + b.publicStr);
 	      // -- not accessible
 	      // System.out.println(b.protectedStr);
 	      // System.out.println(b.defaultStr);
 	      // System.out.println(b.privateStr);
 	      }
}</pre>
	    <pre class="codeblock">--------------------------------------------------------------------------------</pre>
	    <pre class="codeblock">import packageA.*;
 	      import packageB.*;</pre>
	    <pre><span class="codeblock">// -- testing class
 	      public class TestProtection {
 	      public static void main(String[] args) {
 	      // -- all classes are public, so class TestProtection
 	      // -- has access to all of them
 	      new Base().print();
 	      new SubA().print();
 	      new AnotherA().print();
 	      new SubB().print();
 	      new AnotherB().print();
</span> 	      }
 	}</pre>
	    <p># private is the most restrictive access level<br />
	      #     a private member is accessible only
	      in the class in which it is defined<br />
	      #     private members are not inherited by
	      the subclasses</p>
	    <h4>The following two block of codes have the same logic:</h4>
	    <pre class="codeblock">a = b &lt; c ? d : e;</pre>
  <pre><span class="codeblock">if ( b &lt;c )<br />
       a = b;<br />
   else<br />
       a = e;</span><br>
  </pre>
  </div>
    <!-- InstanceEndEditable --></div><!-- end of rightcolumn div -->
</div><!-- end of container div -->

<div id="footer">
	<p>Website design by <a href="../index.html">Kevin Mu Qing</a>; Hosting by <a href="http://www.jimlei.com" target="_blank">Jim Xianyu Lei</a></p>
</div>

</body>
<!-- InstanceEnd --></html>
